package com.hdhere.domain.media;

import com.hdhere.domain.common.BaseEntity;
import com.hdhere.domain.common.enums.RowState;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.RandomStringUtils;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.sql.Time;
import java.util.Base64;

@Entity
@Table(name = "video", schema = "media")
public class Video extends BaseEntity{

  private static final long serialVersionUID = 1L;

  @ApiModelProperty(value = "记录ID")
  @Id
  @Column(columnDefinition="binary(20)", length = 20)//sql server中要加length限制，否则是varbinary(255)
  private byte[] id;

  @ApiModelProperty(value = "名称")
  @Column(length = 300, columnDefinition="nvarchar(200)")
  protected String name;

  @ApiModelProperty(value = "标准名")
  @Column(length = 200, columnDefinition="nvarchar(200)")
  private String nameStd;

  @ApiModelProperty(value = "目录")
  private Long cateId;

  @ApiModelProperty(value = "目录路径")
  @Column(length = 80)
  private String catePath;

  @ApiModelProperty(value = "目录名")
  @Column(length = 80, columnDefinition="nvarchar(80)")
  private String cateName;

  @ApiModelProperty(value = "科目名")
  @Column(length = 80, columnDefinition="nvarchar(80)")
  private String subject;

  @ApiModelProperty(value = "设备Id")
  @Column(columnDefinition="tinyint")
  private short deviceId;

  @ApiModelProperty(value = "发布状态")
  @Column(columnDefinition="tinyint")
  private short postState;

  @ApiModelProperty(value = "格式(概况)")
  @Column(length = 30)
  private String generalFormat;

  @ApiModelProperty(value = "文件大小")
  private Long fileSize;

  @ApiModelProperty(value = "持续时间(概况)")
  @Column(columnDefinition="time(3)")
  private java.sql.Time generalDuration;

  @ApiModelProperty(value = "平均混合码率")
  private Integer overallBitRate;

  @ApiModelProperty(value = "格式(视频)")
  @Column(length = 15)
  private String format;

  @ApiModelProperty(value = "持续时间(视频)")
  @Column(columnDefinition="time(3)")
  private java.sql.Time duration;

  @ApiModelProperty(value = " 码率(视频)")
  private Integer bitRate;

  @ApiModelProperty(value = "宽度")
  private Short width;

  @ApiModelProperty(value = "高度")
  private Short height;

  @ApiModelProperty(value = "扫描类型")
  @Column(columnDefinition = "char(1)")
  private String scanType;

  @ApiModelProperty(value = "帧数")
  private Integer frames;

  @ApiModelProperty(value = "帧率")
  @Column(precision = 5,scale = 3,columnDefinition = "decimal(5,3)")//columnDefinition = "double(5,3) default '10.000'"
  private double fps;

  public void resetData(){
    if(getId() == null || getId().length == 0) {
      setId(Base64.getDecoder().decode(RandomStringUtils.randomAlphanumeric(8)));
      setPostState(RowState.Invalid.getId());
    }
  }

  public byte[] getId() {
    return id;
  }

  public void setId(byte[] id) {
    this.id = id;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getNameStd() {
    return nameStd;
  }

  public void setNameStd(String nameStd) {
    this.nameStd = nameStd;
  }

  public Long getCateId() {
    return cateId;
  }

  public void setCateId(Long cateId) {
    this.cateId = cateId;
  }

  public String getCatePath() {
    return catePath;
  }

  public void setCatePath(String catePath) {
    this.catePath = catePath;
  }

  public String getCateName() {
    return cateName;
  }

  public void setCateName(String cateName) {
    this.cateName = cateName;
  }

  public void setFps(double fps) {
    this.fps = fps;
  }

  public String getSubject() {
    return subject;
  }

  public void setSubject(String subject) {
    this.subject = subject;
  }

  public short getDeviceId() {
    return deviceId;
  }

  public void setDeviceId(short deviceId) {
    this.deviceId = deviceId;
  }

  public short getPostState() {
    return postState;
  }

  public void setPostState(short postState) {
    this.postState = postState;
  }

  public String getGeneralFormat() {
    return generalFormat;
  }

  public void setGeneralFormat(String generalFormat) {
    this.generalFormat = generalFormat;
  }

  public Long getFileSize() {
    return fileSize;
  }

  public void setFileSize(Long fileSize) {
    this.fileSize = fileSize;
  }

  public Time getGeneralDuration() {
    return generalDuration;
  }

  public void setGeneralDuration(Time generalDuration) {
    this.generalDuration = generalDuration;
  }

  public Integer getOverallBitRate() {
    return overallBitRate;
  }

  public void setOverallBitRate(Integer overallBitRate) {
    this.overallBitRate = overallBitRate;
  }

  public String getFormat() {
    return format;
  }

  public void setFormat(String format) {
    this.format = format;
  }

  public Time getDuration() {
    return duration;
  }

  public void setDuration(Time duration) {
    this.duration = duration;
  }

  public Integer getBitRate() {
    return bitRate;
  }

  public void setBitRate(Integer bitRate) {
    this.bitRate = bitRate;
  }

  public Short getWidth() {
    return width;
  }

  public void setWidth(Short width) {
    this.width = width;
  }

  public Short getHeight() {
    return height;
  }

  public void setHeight(Short height) {
    this.height = height;
  }

  public String getScanType() {
    return scanType;
  }

  public void setScanType(String scanType) {
    this.scanType = scanType;
  }

  public Integer getFrames() {
    return frames;
  }

  public void setFrames(Integer frames) {
    this.frames = frames;
  }

  public Double getFps() {
    return fps;
  }

  public void setFps(Double fps) {
    this.fps = fps;
  }
}